package com.guigu.youxuan.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.guigu.youxuan.mapper.WarehouseDetailsMapper;
import com.guigu.youxuan.pojo.Warehouse;
import com.guigu.youxuan.pojo.WarehouseDetails;
import com.guigu.youxuan.service.IWarehouseDetailsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author liweixin
 * @since 2024-05-15
 */
@Service
public class WarehouseDetailsServiceImpl extends ServiceImpl<WarehouseDetailsMapper, WarehouseDetails> implements IWarehouseDetailsService {
    @Autowired
    private  WarehouseDetailsMapper warehouseDetailsMapper;

    @Autowired
    private WarehouseDetailsMapper wareDetailsMapper;

    /**
     * 分页查询仓库商品表
     * @param currentPage
     * @param pageSize
     * @return
     */
    @Override
    public PageInfo<WarehouseDetails> DynamicListPage(int currentPage, int pageSize) {
        PageHelper.startPage(currentPage,pageSize);
        List<WarehouseDetails> warehouses=warehouseDetailsMapper.list();
        PageInfo<WarehouseDetails> pageInfo=new PageInfo<>(warehouses);
        return pageInfo;
    }

    @Override
    public Integer queryGoodsAmount(Long goodsId) {
        QueryWrapper<WarehouseDetails> wrapper = new QueryWrapper<>();
        wrapper.eq("goods_id",goodsId);
        wrapper.eq("is_deleted",0);
        List<WarehouseDetails> list = this.list(wrapper);
        int num = 0;
        for (WarehouseDetails w : list) {
            num += w.getNowAmount();
        }
        return num;
    }

    @Override
    public WarehouseDetails queryWarehouseByGid(Long goodsId) {
        WarehouseDetails warehouseDetails = wareDetailsMapper.queryWarehouseByGid(goodsId);
        return warehouseDetails;
    }
}
